<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>mapSever</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <style>
    body,
    html,
    #container {
        overflow: hidden;
        width: 100%;
        height: 100%;
        margin: 0;
        font-family: "微软雅黑";
    }
    </style>
    <script src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak=6n3I1KlUFn92aHDNqeayzXZX"></script>
    <script type="text/javascript" src="{{url_for('static', filename='jquery.min.js')}}"></script>
</head>
<body>
    <div id="container"></div>
</body>
</html>
<script>
    $(function() {
        var map = new BMapGL.Map('container');
        map.enableScrollWheelZoom(true);
        setInterval(function() {
            $.ajax({
                url: "/getPoints",
                type: "get",
                success: function(data) {
                    result=eval(data)
                    if(result.length==0) {
                        return;
                    }
                    map.clearOverlays();
                    map.centerAndZoom(new BMapGL.Point(result[0], result[1]), 22);
                    // 创建点标记
                    var cameraPoint = new BMapGL.Point(result[0], result[1]);
                    var targetPoint = new BMapGL.Point(result[2], result[3]);
                    var dis = map.getDistance(cameraPoint, targetPoint);
                    var opts = {
	                width : 200,     // 信息窗口宽度
	                height: 50,     // 信息窗口高度
	                title : "相机"  // 信息窗口标题
	            }
	            var infoWindow = new BMapGL.InfoWindow("目标和我相距:"+dis+"米", opts);  // 创建信息窗口对象 
	            map.openInfoWindow(infoWindow, cameraPoint); //开启信息窗口
                    var marker1 = new BMapGL.Marker(cameraPoint);
                    var marker2 = new BMapGL.Marker(targetPoint);
                    // 在地图上添加点标记
                    map.addOverlay(marker1);
                    map.addOverlay(marker2);
                }
            });
        }, 2000);
    });
</script>
